<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="学生姓名">
    <el-col :span="5"> 
    <el-input v-model="form.name"></el-input>
    </el-col>
  </el-form-item>
  <el-form-item label="学号">
    <el-col :span="5">
    <el-input v-model="form.number"></el-input>
    </el-col>
  </el-form-item>
  <el-form-item label="所在班级">
    <el-select v-model="form.c_id" placeholder="请选择班级" @change="getClassByG_id">
      <el-option
        v-for="item in classes"
        :key="item.id"
        :label="item.cname"
        :value="item.id"
      >
      </el-option>
    
    </el-select>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即添加</el-button>
    <el-button>取消</el-button>
  </el-form-item>
</el-form>
  </div>
</template>
<script>
import axios from 'axios';
import commons from "../../../assets/commons";
export default {
    data() {
      return {
        form: {
            name: '',
            number:'',
            c_id:1
        },
        classes:[]
      }
    },
    methods: {
      onSubmit() {
        let params = new URLSearchParams();
      //封装数据
        params.append("name", this.form.name);
        params.append("number", this.form.number);
        params.append("c_id", this.form.c_id);
        axios.post("http://localhost:8080/student_account_management/addStuUser", params).then(res => { 
          if(res.data.code == 200){
            this.$message({
              type: "success",
              message:res.data.message
            });    
          }
          if(res.data.code == 201){
          this.$message({
            type: "error",
            message:res.data.message
          });    
          }
        });
      },
       getClassByG_id(){
       axios.get(
          commons.baseUrl +
            "student_account_management/getClassByG_id?g_id=" +1 
        ).
       then(res => {
          if(res.data.code == 200){
            this.classes=res.data.data;
          }
       });
    }
     
    },
     mounted(){
       this.getClassByG_id();
      
      },computed: {}
  }
</script>
<style scoped></style>
